package o;

import android.content.Context;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.hwCloudJs.d.d;
import java.util.UUID;

public class bjy {
    private final Context ˊ;

    public static class c {
        public final String ˎ;
        public final int ˏ;
        public final int ॱ;

        private c(int i, String str) {
            this.ˏ = i;
            this.ॱ = ˏ(i);
            this.ˎ = str;
        }

        public String toString() {
            return ॱ(this.ˏ) + "/" + this.ॱ + ": " + this.ˎ;
        }

        private int ˏ(int i) {
            switch (i) {
                case 2:
                    return 0;
                default:
                    return 9;
            }
        }

        private static String ॱ(int i) {
            switch (i) {
                case 1:
                    return "udid";
                case 2:
                    return "imei|meid";
                case 3:
                    return "serial_hash";
                case 4:
                    return "uuid_hash";
                default:
                    return d.b;
            }
        }
    }

    public bjy(@NonNull Context context) {
        if (context == null) {
            throw new NullPointerException("context must not be null.");
        }
        this.ˊ = context;
    }

    @NonNull
    public c ॱ() {
        c cVar = null;
        String ˊ = bjx.ˊ();
        if (ˊ == null) {
            cVar = ˋ();
        } else if (!ˊ.isEmpty()) {
            cVar = new c(1, ˊ);
        }
        if (cVar != null) {
            return cVar;
        }
        cVar = ˊ();
        if (cVar == null) {
            return ˏ();
        }
        return cVar;
    }

    @Nullable
    public c ˋ() {
        TelephonyManager telephonyManager = (TelephonyManager) this.ˊ.getSystemService("phone");
        if (telephonyManager == null) {
            return null;
        }
        Object deviceId;
        try {
            deviceId = telephonyManager.getDeviceId();
        } catch (SecurityException e) {
            deviceId = "";
        }
        if (TextUtils.isEmpty(deviceId)) {
            return null;
        }
        return new c(2, deviceId);
    }

    @Nullable
    private c ˊ() {
        String ˏ = bjx.ˏ();
        if (ˏ.isEmpty()) {
            return null;
        }
        return new c(3, bkq.ˋ(bkn.ॱ(ˏ)));
    }

    @NonNull
    private c ˏ() {
        SharedPreferences sharedPreferences = this.ˊ.getSharedPreferences("com.huawei.appgallery.os.HwDeviceIdEx", 0);
        String string = sharedPreferences.getString("uuid.hash", "");
        if (TextUtils.isEmpty(string)) {
            string = bkq.ˋ(bkn.ॱ(UUID.randomUUID().toString()));
            sharedPreferences.edit().putString("uuid.hash", string).apply();
        }
        return new c(4, string);
    }
}
